'use strict';

// const nunjucks = require('nunjucks');
// const env = new nunjucks.Environment();
//
// env.addFilter('typeMapper', function(type) {
//   switch (type) {
//     case '1': return 'RESEARCH NEWS';
//     case '0': return 'DAILY';
//     default: return 'RESEARCH NEWS';
//   }
// });

exports.typeMapper = type => {
  switch (type) {
    case '1': return 'RESEARCH NEWS';
    case '2': return 'DAILY';
    default: return 'RESEARCH NEWS';
  }
};

exports.monthFilter = time => {
  if (!time) {
    return '';
  }
  const month = [ 'Jan.', 'Feb.', 'Mar.', 'Apr.', 'May', 'June', 'July', 'Aug.', 'Sept.', 'Oct.', 'Nov.', 'Dec.' ];
  const monthStr = time.split('-')[1];
  const num = Number(monthStr);
  return month[num - 1];
};

exports.dayFilter = time => {
  if (!time) {
    return '';
  }
  return time.split('-')[2];
};

exports.timeEnFilter = time => {
  if (!time) {
    return '';
  }
  const month = [ 'Jan.', 'Feb.', 'Mar.', 'Apr.', 'May', 'June', 'July', 'Aug.', 'Sept.', 'Oct.', 'Nov.', 'Dec.' ];
  const timeStr = time.split('-');
  const monthStr = timeStr[1];
  const yearStr = timeStr[0];
  const dayStr = timeStr[0];
  const num = Number(monthStr);
  return `${dayStr} ${month[num - 1]} ${yearStr}`;
};
